package cn.jdy.plugins.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.entity.News;
import cn.jdy.plugins.service.ColumnchartService;


@Controller
@RequestMapping("/Columnchar")
public class ColumnchartCtrl extends BaseCtrl{
	
	@Autowired
	private ColumnchartService columnchartService;
	
	
	
	
	/**
	 * 
	 * @param homeWork
	 * @return 局直用稿统计
	 */
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/lists.html")
	public ModelAndView lists(String time) {
		ModelAndView mv = new ModelAndView("columncharts/ColumnchartList.jsp");
	//	mv.addObject("listmount",columnchartService.getMonth(time)); 
		mv.addObject("listyear",columnchartService.getyear());
		//襄阳市公安局，需要加入当前时间段周数
	    Date datetime = new Date();
		int weekdays = datetime.getDay();
	    mv.addObject("weekdays",weekdays);//日一二三四五六=0123456
		List<Map<String, String>> listname=null;
		if(time==""||time==null){
			time=columnchartService.getMonths().toString().substring(10, 17);
			 listname=columnchartService.getCounts(time);
		}else{
			 listname=columnchartService.getCounts(time);
		}
		mv.addObject("lists",listname);
        String realname="";
        String realsum="[";
        List list=new ArrayList<>();
        for (int i = 0; i < listname.size(); i++) {
        	Map<String, String> mp=listname.get(i);
        	 List  rnam=new ArrayList<>();
        	if(i==0){
        		realname =realname+mp.get("realname");
        		}
        	else{
        		realname =realname+","+mp.get("realname");
        		}
        	rnam.add("'"+mp.get("realname")+"'");
        	rnam.add(String.valueOf(mp.get("c1")));
        	list.add(rnam);
        }
        realsum=realsum+"]";
        mv.addObject("relist",list);
        mv.addObject("data11",time);
	    return mv;
	}
	
	/**
	 * @param homeWork
	 * @return 各地用稿统计
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/listsum.html")
	public ModelAndView listsum(String time) {
		
		ModelAndView mv = new ModelAndView("columncharts/ColumnchartLists.jsp");
	    
		mv.addObject("listyear",columnchartService.getyear());		
		//襄阳市公安局，需要加入当前时间段周数
	    Date datetime = new Date();
	    int weekdays = datetime.getDay();
		mv.addObject("weekdays",weekdays);//日一二三四五六=0123456
		
		List<Map<String, String>> listname=null;
		if(time==""||time==null){
			time=columnchartService.getMonths().toString().substring(10, 17);
			 listname=columnchartService.getCount(time);
			
		}else{
			 listname=columnchartService.getCount(time);
		}
		mv.addObject("lists",listname);
        String realname="";
        String realsum="[";
        List list=new ArrayList<>();
        for (int i = 0; i < listname.size(); i++) {
        	Map<String, String> mp=listname.get(i);
        	 List  rnam=new ArrayList<>();
        	if(i==0){
        		realname =realname+mp.get("realname");
        		//realsum=realsum+"{ y:"+String.valueOf(mp.get("c1"))+", color: 'red', name: '20' }";
        		}
        	else{
        		realname =realname+","+mp.get("realname");
        		//realsum=realsum+","+"{ y:"+String.valueOf(mp.get("c1"))+", color: 'red', name: '20' }";
        		}
        
        	rnam.add("'"+mp.get("realname")+"'");
        	rnam.add(String.valueOf(mp.get("c1")));
        
        	list.add(rnam);
        	
        }
        realsum=realsum+"]";
       // mv.addObject("realsum",realsum);
       // mv.addObject("realname",realname);
        mv.addObject("relist",list);
        mv.addObject("data",time);
        mv.addObject("data11",time);
	    return mv;
	}
	
	
	/**
	 * @param homeWork
	 * @return 浏览排名
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/liulan.html")
	public ModelAndView liulan() {
		
		ModelAndView mv = new ModelAndView("columncharts/Liulan.jsp");
		
		
		 List<Map<String, String>> listname=columnchartService.getLiulan();
			
		
		mv.addObject("lists",listname);
		
		//襄阳市公安局，需要加入当前时间段周数
		Date datetime = new Date();
		int weekdays = datetime.getDay();
		mv.addObject("weekdays",weekdays);//日一二三四五六=0123456
        
        String realname="";
        String realsum="[";
      
        List list=new ArrayList<>();
        for (int i = 0; i < listname.size(); i++) {
        	Map<String, String> mp=listname.get(i);
        	 List  rnam=new ArrayList<>();
        	if(i==0){
        		realname =realname+mp.get("aa");
        		}
        	else{
        		realname =realname+","+mp.get("aa");
        		}
        
        	rnam.add("'"+mp.get("aa")+"'");
        	rnam.add(String.valueOf(mp.get("bb")));
        
        	list.add(rnam);
        	
        }
        realsum=realsum+"]";
       // mv.addObject("realsum",realsum);
       // mv.addObject("realname",realname);
        mv.addObject("relist",list);

       // mv.addObject("data",time);

	    return mv;
	}
}
